home *** CD-ROM | disk | FTP | other *** search
- /* PositionDialog.c */
- /*
- * DTS AddressOMatic Sample
- * PositionDialog.c
- * Copyright © 1993 Apple Computer Inc. All rights reserved.
- *
- * PositionDialog relocates a dialog or alert so it is centered on the main screen,
- * 1/3 down from the top. This is a utility routine that is generally independent
- * of the AddressOMatic. It is not quite correct as it doesn't compensate for
- * multiple screens.
- */
- #include "AddressOMaticTest.h"
-
- /*
- * No side-effects allowed
- */
- #define Max(a, b) (((a) > (b)) ? (a) : (b))
-
- /*
- * PositionDialog
- * Position a dialog given its resource type and id.
- */
- void
- PositionDialog(
- ResType dialogType,
- short dialogID
- )
- {
- Handle template;
-
- template = GetResource(dialogType, dialogID);
- if (template != NULL)
- PositionRect((Rect *) (*template));
- }
-
- /*
- * PositionRect
- * Given a rectangle, reposition it so it is centered on the main screen, and
- * located at the top 1/3 of the screen. This version assumes that all dialogs
- * (or whatever) will actually fit on the screen. It also does not look at
- * the display that the FrontWindow is located on, but assumes that it will
- * always draw on the main screen.
- */
- void
- PositionRect(
- Rect *boundsPtr
- )
- {
- short leftEdge;
- short topEdge;
- short screenWidth;
- short screenHeight;
-
- screenWidth = width(qd.screenBits.bounds);
- screenHeight = height(qd.screenBits.bounds);
- leftEdge = Max((screenWidth - width(*boundsPtr)) / 2, 0);
- topEdge = (screenHeight - height(*boundsPtr)) / 3;
- topEdge = Max(topEdge, GetMBarHeight() + 1);
- boundsPtr->right = width(*boundsPtr) + leftEdge;
- boundsPtr->left = leftEdge;
- boundsPtr->bottom = height(*boundsPtr) + topEdge;
- boundsPtr->top = topEdge;
- }
-